package com.example.travelcomponentdemo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.EditText;

public class EditTextAsFacebook extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edittext_as_facebook);
		
		final EditText text = (EditText) findViewById(R.id.editText1);
		
		String staticText = "- at ";
		String address = "DC Tower";
		final SpannableString span = new SpannableString(staticText + address);
		span.setSpan(new ForegroundColorSpan(Color.LTGRAY), 0, 
				staticText.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		span.setSpan(new ClickableSpan() {
			
			@Override
			public void onClick(View widget) {
				Intent i = new Intent(getApplicationContext(), SliderOnOff.class);
				startActivity(i);
			}
		}, staticText.length(), 
				staticText.length() + address.length(), 
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		
		text.setText(span);
		text.setMovementMethod(LinkMovementMethod.getInstance());
//		Selection.setSelection(span, text.getText().length() - 1);
//		
//		text.addTextChangedListener(new TextWatcher() {
//
//	        @Override
//	        public void onTextChanged(CharSequence s, int start, int before, int count) {
//	            // TODO Auto-generated method stub
//
//	        }
//
//	        @Override
//	        public void beforeTextChanged(CharSequence s, int start, int count,
//	                int after) {
//	            // TODO Auto-generated method stub
//
//	        }
//
//	        @Override
//	        public void afterTextChanged(Editable s) {
//	            Selection.setSelection(span, text.getText().length() - 1);
//	        }
//
//	    });
	}
}
